<template>
    <div v-loading="loading">
        <el-card body-style="padding:10px" class="box-card">
            <el-input clearable placeholder="请输入银行卡号" size="small" style="width: 200px;"
                v-model="query.bank_card"></el-input>

            <!-- 根据type选择 -->
            <el-select v-model="query.status" placeholder="请选择提现状态">
                <el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value">
                </el-option>
            </el-select>

            <el-button @click="page=1;init()" size="small" type="primary" style="margin-left: 10px;">搜索</el-button>
            <el-button @click="toForm()" size="small" style="margin-left: 10px" type="success">添加</el-button>
        </el-card>

        <el-dialog title="提现秀币" :visible.sync="visible" width="800px">
            <el-form :model="form"  label-width="120px">

                <el-form-item label="秀币">
                    <el-input placeholder="请输入提现秀币" style="width: 500px" v-model="form.balance"></el-input>
                </el-form-item>

                <el-form-item label="2fas验证码">
                    <el-input placeholder="请输入2fas验证码" style="width: 500px" v-model="form.verify_code"></el-input>
                </el-form-item>

                <!-- 选择银行卡信息 -->
                <el-form-item label="选择银行卡信息"  >
                    <el-select v-model="form.bank_id" placeholder="选择银行卡信息"  style="width: 500px">
                        <el-option v-for="item in tableData" :key="item.value" :label="item.card_number" :value="item.id">
                        </el-option>
                    </el-select>
                </el-form-item>

            </el-form>
            <div class="dialog-footer" slot="footer">
                <el-button @click="closeBox">取 消</el-button>
                <el-button @click="submit"  :loading="submitComplete" type="primary">确 定</el-button>
            </div>
        </el-dialog>

        <el-card body-style="padding:10px" class="box-card mt-10">
            <el-table :data="data" max-height="440px" size="small" style="width: 100%">
                <el-table-column label="ID" prop="id"></el-table-column>
                <!-- <el-table-column label="代理ID" prop="agent_id" >
                    <template slot-scope="scope">
                        <UserInfo :user_id="scope.row.agent_id" v-if="scope.row.agent_id" :showBtn="false"></UserInfo>
                    </template>
                </el-table-column> -->
                <!-- <el-table-column label="银行卡编码" prop="bank_code"></el-table-column> -->
                <el-table-column label="银行名称" prop="bank_name"></el-table-column>
                <el-table-column label="真实姓名" prop="real_name"></el-table-column>
                <el-table-column label="银行卡号" prop="bank_card"></el-table-column>
                <!-- <el-table-column label="开户行地址" prop="bank_address"></el-table-column> -->
                <el-table-column label="提现秀币" prop="balance"></el-table-column>
                <el-table-column label="到账金额" prop="money" width="100px"></el-table-column>


                <el-table-column label="手续费" prop="fee"></el-table-column>

                <el-table-column label="提现状态" prop="status" width="100px">
                    <template slot-scope="scope">
                        <el-tag v-if="scope.row.status == 0" type="warning">待审核</el-tag>
                        <el-tag v-else-if="scope.row.status == 1" type="success">已通过</el-tag>
                        <el-tag v-else-if="scope.row.status == 2" type="danger">已拒绝</el-tag>

                    </template>
                </el-table-column>
                <el-table-column label="添加时间" sortable prop="created_at"></el-table-column>
                <el-table-column label="操作">
                    <template slot-scope="scope">
                        <div>
                            <el-button size="mini" slot="reference" type="success" style="padding: 10px"
                                @click="toDetails(scope.row.id)">详情</el-button>
                        </div>
                    </template>
                </el-table-column>
            </el-table>
        </el-card>
        <!-- 分页组件 -->
        <el-card body-style="padding:10px" class="box-card mt-10">
            <el-pagination :current-page="page" :total="total" @current-change="pageChange" @size-change="sizeChange"
                layout="total, prev, pager, next, sizes" style="margin-top: 8px;" />
        </el-card>
    </div>
</template>
      
<script>
import treeSelect from '@/components/SelectTree/index'
import list from "@/api/bank.json"
import medium from '@/components/medium/index'
import initData from '@/mixins/index'
export default {
    mixins: [initData],
    components: {
        treeSelect,
        medium
    },
    data() {
        return {
            query: {
                status: null,
                bank_card: '',
                verify_code:''
            },
            value: '',
            options: [
                {
                    value: 0,
                    label: '待审核'
                }, {
                    value: 1,
                    label: '已通过'
                }, {
                    value: 2,
                    label: '已拒绝'
                }
            ],
            typeList: list,
            visible: false,
            loading: false,
            tableData: [],
            visible: false,
            form: {
                bank_id: '', //银行卡信息ID 
                balance: ''  //提现使用多少秀币     
            },
            submitComplete:false
        }
    },
    mounted() {
        //this.getworksList()
        this.beforeInit()
        this.getDataList()


    },
    methods: {
        beforeInit() {
            this.url = "/withdraw/index"
            this.init() //重新请求数据
            console.log("data", this.data)
        },
        selectFun(val) {
            this.query.bank_name = val
        },

        toDetails(id) {
            this.$router.push({ path: "/withdraw-details?id=" + id });
        },


        closeBox() {
            this.type = 'create'
            this.visible = false
        },

        getDataList() {
            let that = this
            this.$request.get('/bank/index').then((res) => {
                that.tableData = res
                console.log('tableData', res)
            })
        },

        toForm(form = null) {
            this.visible = true //打开弹出框
            if (form != null) {
                this.type = 'update'
                this.id = form.id
                this.show = form.disable == 0 ? false : true
            } else {
                this.type = 'create'
                this.form = {
                    bank_id: '', //银行卡信息ID 
                    balance: ''  //提现使用多少秀币     
                }
            }
        },

        //提交
        submit() {
            if (this.submitComplete) return
            this.submitComplete = true
            if (!(this.form.balance && this.form.bank_id)) {
                this.$message({
                    message: '请将信息填写完整！',
                    type: 'warning'
                });
                this.submitComplete = false
                return
            }
            if (this.type == 'create') {
                this.$request.post('/withdraw/create', this.form).then((res) => {
                    this.$message({
                        message: '添加成功',
                        type: 'success'
                    });
                    this.submitComplete = false
                    this.init() //重新请求数据
                    this.closeBox()

                }).catch((error)=>{
                this.submitComplete = false
                });
            } else {
                this.$request.put('/bank/update/' + this.id, this.form).then((res) => {
                    console.log(res)
                    this.$message({
                        message: '修改成功',
                        type: 'success'
                    });
                    this.submitComplete = false
                    this.init() //重新请求数据
                    this.closeBox()
                }).catch((error)=>{
                this.submitComplete = false
                });
            }
        },



    },
}
</script>
      
<style lang="scss" scoped>
.butBox {
    background-color: rgb(219, 219, 219);
    border: none;
    color: #555;
}

.flex {
    display: flex;
}
</style>